<?php
/**
 * 后台游戏标签表操作模型
 * @author Liuwei
 */
class MTag extends MY_Model {

	const STATE_ENABLE = 1;
	const STATE_DISABLE = 0;
	protected $table = 'tag';
	private $filter = array();

    function __construct() {
        parent::__construct();
    }
    
	public function getList($limit, $sort=false){
		$this->db->select('*');
		$this->db->from($this->table);
		$this->db->limit($limit['limit'],$limit['offset']);
		$this->formfilter->doFilter();
		if($sort){
			$this->db->order_by('create_time', 'asc');
		}else{
			$this->db->order_by('id', 'desc');
		}
		$query = $this->db->get();
		return $query->result();
	}
	public function getCount(){
		$this->db->select('count(*) as num');
		$this->db->from($this->table);
		$this->formfilter->doFilter();
		$tmp = $this->db->get()->result();
		return (int)$tmp[0]->num;
	}
	
	public function delete($id, $update_time){
		$this->db->where('id', $id);
		$this->db->where('update_time', $update_time);
		$ret = $this->db->delete($this->table);
		if($ret || $this->db->affected_rows() >= 1){
			return true;
		}
		return false;
	}
	
	/**
     * 
     * 根据游戏ID查询游戏信息
     * @param $id 游戏ID
     */
	public function getById($id){
		$query = $this->db->where('id',$id)->get($this->table);
		return $query->row();
	}
	
}
